package com.student.Activitys.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.student.Activitys.R;
import com.student.Activitys.bean.ScheduleWeekBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * 项目名称：智慧校园学生端
 * 类描述：周课表 课表内容 adapter
 * 创建人：张飞祥
 * 创建时间：2017/9/25 15:32
 * 修改人：张飞祥
 * 修改时间：2017/9/25 15:32
 * 修改备注：
 */
public class ScheduleWeekAdapter extends BaseAdapter{


    private Context context;
    private List<ScheduleWeekBean> list;
    private boolean today = false;
    private LayoutInflater inflater = null;

    public ScheduleWeekAdapter(Context context,List<ScheduleWeekBean> list,boolean today) {
        this.context = context;
        this.list = list;
        this.today = today;
        this.inflater= LayoutInflater.from(context);  //这里就是确定你listview在哪一个layout里面展示
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_schedule_week, null);
            //把convertView中的控件保存到viewHolder中
            holder.text = (TextView)convertView .findViewById(R.id.item_schedule_text);
            //通过setTag将ViewHolder与convertView绑定
            convertView.setTag(holder);
        }else{
            //通过调用缓冲视图convertView，然后就可以调用到viewHolder,viewHolder中已经绑定了各个控件，省去了findViewById的步骤
            holder = (ViewHolder)convertView.getTag();
        }
        holder.text.setText(list.get(i).getKCM());
        //判断是否 为今天，true: 字体颜色变为红色
        if (today == true){
            holder.text.setTextColor(Color.RED);  //设置字体为红色
        }
        //适配
        AutoUtils.auto(convertView);
        return convertView;
    }

    static class ViewHolder
    {
        public TextView text;
    }
}
